package com.wc5818.wcDanbrInfo.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wc5818.common.AjaxResult;
import com.wc5818.wcDanbrInfo.entity.WcDanbrinfo;
import com.wc5818.wcDanbrInfo.mapper.WcDanbrinfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 担保人信息 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2020-03-20
 */
@RestController
@RequestMapping("/wcDanbrInfo")
public class WcDanbrinfoController {
    @Autowired
    WcDanbrinfoMapper wcDanbrinfoMapper;

    @GetMapping("/selectByOrderNum")
    public Object selectByOrderNum(String orderId) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);

        List list = wcDanbrinfoMapper.selectList(new QueryWrapper<WcDanbrinfo>().eq("orderNum", orderId));
        if(list != null  && list.size() > 0) {
            ajaxResult.setSuccess(true);
            ajaxResult.setData(list.get(0));
        }

        return ajaxResult;
    }

    @PostMapping("/saveOrUpdate")
    public Object saveOrUpdate(@RequestBody WcDanbrinfo wcDanbrinfo) {
        AjaxResult ajaxResult = new AjaxResult();
        ajaxResult.setSuccess(false);

        if(wcDanbrinfo.getId() == null) {
            if(wcDanbrinfoMapper.insert(wcDanbrinfo) > 0)
                ajaxResult.setSuccess(true);
        } else {
            if(wcDanbrinfoMapper.updateById(wcDanbrinfo) >= 0)
                ajaxResult.setSuccess(true);
        }

        return ajaxResult;
    }
}
